<template>
  <div>
    <p>List</p>
    <ul>
      <li v-for="item in List" :key="item.id">
        姓名-{{ item.name }}年龄-{{ item.age }}
      </li>
    </ul>
    <button @click="sendDataToParent">向父组件传递数据</button>
    <button @click="destroyList">卸载list组件</button>
  </div>
</template>

<script>
export default {
  name: "List",
  data() {
    return {
      List: [
        { id: "001", name: "laoliu", age: 37 },
        { id: "002", name: "xiangyang", age: 35 },
        { id: "003", name: "awei", age: 38 },
      ],
    };
  },
  methods: {
    sendDataToParent() {
      this.$emit("sendData", this.List);
    },
    destroyList() {
      // 卸载List组件
      this.$destroy();
    },
  },
  beforeDestroy() {
    // 真正的解绑
    this.$off("sendData");
  },
};
</script>

<style>
</style>